package com.bizmerce.rnd.oms.reporting.web;

import java.awt.Color;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.document.AbstractPdfView;

import com.lowagie.text.Cell;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class Korea_US extends AbstractPdfView {

	protected void buildPdfDocument(Map map, Document document, PdfWriter writer,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		/**FONTS*/
		BaseFont baseFont = BaseFont.createFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED);
		BaseFont enbaseFont = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		Font headerFont = new Font(baseFont, 14, Font.BOLD, Color.black);
		Font titleFont = new Font(baseFont, 14, Font.BOLD);
		Font normalFont = new Font(baseFont, 8, Font.NORMAL);
		Font boldFont = new Font(baseFont, 10, Font.BOLD);
		
		/**TITLE*/
		Paragraph paragraph;
		paragraph = new Paragraph("<양식 9>한-미 FTA 원산지증명서 권고서식", headerFont);
		document.add(paragraph);

		/**별지 제 호의 서식*/
		PdfContentByte cb = writer.getDirectContent();
        cb.beginText();
        cb.setFontAndSize(baseFont, 10);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, "[별지 제 호의 서식]", 35, 755, 0);
        cb.endText();
		
        /**Ref.No.*/
		cb.setLineWidth(1f);
		cb.moveTo(380, 749);
		cb.lineTo(380, 775);
		cb.lineTo(559, 775);
		cb.lineTo(559, 749);
		cb.stroke();
		cb.beginText();
		cb.setFontAndSize(enbaseFont, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_LEFT,"Ref.No. : ",390, 765, 0);
		cb.setFontAndSize(baseFont, 9);
		cb.showText("47260-00141");
		cb.setFontAndSize(baseFont, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_LEFT,"(발급번호)",385, 753, 0);
		paragraph = new Paragraph(" ");
		document.add(paragraph);
		cb.endText();
		
		/**TABEL INFORMATION*/
		Table table;
		Cell cell;
		Chunk chunk;
		
		table = new Table(8);
		table.setPadding(3);
		table.setWidth(100);
		int headerwidths[] = { 10, 14, 13, 13, 10, 14, 10, 16};
		table.setWidths(headerwidths);

		cell = new Cell(new Paragraph("CERTIFICATE OF ORIGIN"+"\n"+"KOREA-US FREE TRADE AGREEMENT",titleFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		cell.setColspan(8);
		table.addCell(cell);

		/**1. Exporter*/
		cell = new Cell(new Chunk("1.Exporter"+"\n"+"(수출자)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setRowspan(5);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Name(성명)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("1. 대표자성명",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		/**2. Blanket Period*/
		cell = new Cell(new Chunk("2.Blanket Period(원산지포괄증명기간)"+"\n",normalFont));
		chunk = new Chunk("\n");
		cell.add(chunk);
		chunk = new Chunk("          YYYY      MM    DD                  YYYY      MM    DD"+"\n",normalFont);
		cell.add(chunk);
		chunk = new Chunk("           (년)      (월)     (일)                  (년)      (월)     (일)"+"\n",normalFont);
		float subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("          ");
		chunk = new Chunk("2010",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("      ");
		chunk = new Chunk("08",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("       ");
		chunk = new Chunk("20",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("                   ");
		chunk = new Chunk("2010",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("      ");
		chunk = new Chunk("08",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk.append("       ");
		chunk = new Chunk("20"+"\n",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk = new Chunk("From:........./......../........           To:........./......../........"+"\n"+"(부터)                                         (까지)",normalFont);
		subscript = 15.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		cell.setColspan(4);
		cell.setRowspan(5);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Address(주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("1. 대전광역시 서구 만년동",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Telephone(전화)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("1. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);

		cell = new Cell(new Chunk("Fax(팩스)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("1. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("E-mail(전자주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("1. abcdefg@hanmail.net",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		/**3. Producer*/
		cell = new Cell(new Chunk("3.Producer"+"\n"+"(생산자)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setRowspan(5);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Name(성명)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("3. 대표자성명",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("4.Importer"+"\n"+"(수입자)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setRowspan(5);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Name(성명)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("4. 대표자성명",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Address(주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("3. 대전광역시 서구 만년동",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Address(주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("4. 대전광역시 서구 만년동",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Telephone(전화)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("3. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Telephone(전화)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("4. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);

		cell = new Cell(new Chunk("Fax(팩스)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("3. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("Fax(팩스)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("4. 042-123-4567",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("E-mail(전자주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("3. abcdefg@hanmail.net",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("E-mail(전자주소)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Chunk("4. abcdefg@hanmail.net",normalFont));
		cell.setColspan(2);
		table.addCell(cell);
		
		/**5. 원 산 지 증 명 대 상 물 품 내 역*/
		cell = new Cell(new Paragraph("5. 원 산 지 증 명 대 상 물 품 내 역",boldFont));
		cell.setColspan(8);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		
		cell = new Cell(new Paragraph("Serial No."+"\n"+"(연번)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Paragraph("Description of Good(s)"+"\n"+"(품명-규격)",normalFont));
		cell.setColspan(2);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Paragraph("HS No."+"\n"+"(품목번호 HS 6단위)",normalFont));
		cell.setColspan(2);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Paragraph("Preference Criterion"+"\n"+"(원산지결정기준)",normalFont));
		cell.setColspan(2);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		cell = new Cell(new Paragraph("Country of Origin"+"\n"+"(원산지 국가)",normalFont));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		
		for(int i=0;i<=1;i++){
			cell = new Cell(new Paragraph("1",normalFont));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			table.addCell(cell);
			cell = new Cell(new Paragraph("ZKSC0240-STEELCASE",normalFont));
			cell.setColspan(2);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			table.addCell(cell);
			cell = new Cell(new Paragraph("7326909000",normalFont));
			cell.setColspan(2);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			table.addCell(cell);
			cell = new Cell(new Paragraph("CC+BD 21%",normalFont));
			cell.setColspan(2);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			table.addCell(cell);
			cell = new Cell(new Paragraph("한-ASEAN",normalFont));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			table.addCell(cell);
		}
		
		/**6. Observations*/
		cell = new Cell(new Chunk("6. Observations : ",normalFont));
		cell.setColspan(8);
		chunk = new Chunk("특이사항을 적으세요.",normalFont);
		chunk.append("\n"+"(특이사항)");
		chunk.setFont(normalFont);
		cell.add(chunk);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("I Certify that :"+"\n", normalFont));
		cell.setColspan(8);
		chunk = new Chunk("본인은 다음 사항을 확인합니다."+"\n");
		chunk.append("- The information in this document is true and accurate and I assume the responsibility for proving such representations."+"\n");
		chunk.append("    I understand that I am liable for any false statements or material omissions made on or in connection with this document."+"\n");
		chunk.append("    상기 서식에 기재된 내용은 사실이고 정확하며, 기재된 사항에 대한 책임은 본인에게 있습니다. 이증명서 또는 이와 관련한 허위 진술 또는"+"\n");
		chunk.append("    중대한 사실 누락에 대해서는 본인에게 책임이 있음을 확인합니다."+"\n");
		
		chunk.append("- I agree to maintain, and present upon request, documentation necessary to support this Certificate, and to inform, in writing,"+"\n");
		chunk.append("    all persons to whom the Certificate was given of any changes that would affect the accuracy or validity of this Certificate."+"\n");
		chunk.append("    본인은 이 증명서를 입증하는데 필요한 문서를 보관하며, 요청이 있을 경우 이를 제출할 뿐 아니라, 이 증명서의 정확성이나 유효기간에"+"\n");
		chunk.append("    영향을 미치는 여타 변동사항에 대해서 이 증명서를 받은 관계자들에게 서면으로 통보할 것에 동의합니다."+"\n");
		
		chunk.append("- The goods originate in the territory of one or both Parties and comply with the origin requirements specified for those goods in"+"\n");
		chunk.append("    the Korea - United State of America Free Agreement."+"\n");
		chunk.append("    당해 물품은 대한민국과 미합중국간의 자유무역협정에 따른 원산지결정기준을 충족하고 있음을 확인합니다."+"\n");
		chunk.append("    This Certificate consists of");
		chunk.append("______");
		chunk.append("pages, including all attachments."+"\n");
		chunk.append("    이 증명서는 첨부서류를 포함하여 총");
		chunk.append("______");
		chunk.append("장으로 구성되어 있습니다."+"\n");

		chunk.setFont(normalFont);
		cell.add(chunk);
		table.addCell(cell);
		
		/**7. Authorized Signature*/
		cell = new Cell(new Chunk("7. Authorized Signature : ",normalFont));
		chunk = new Chunk("7. 공인서명",normalFont);
		chunk.append("\n"+"   (서명권자의 서명)");
		chunk.setFont(normalFont);
		cell.setColspan(4);
		cell.add(chunk);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("   Company : ",normalFont));
		chunk = new Chunk("7. 비즈머스",normalFont);
		chunk.append("\n"+"   (회사명)");
		chunk.setFont(normalFont);
		cell.setColspan(4);
		cell.add(chunk);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("   Name :",normalFont));
		chunk = new Chunk("7. 대표자",normalFont);
		chunk.append("\n"+"   (작성자 성명)");
		chunk.setFont(normalFont);
		cell.setColspan(4);
		cell.add(chunk);
		table.addCell(cell);

		cell = new Cell(new Chunk("   Title : ",normalFont));
		chunk = new Chunk("7. 사원",normalFont);
		chunk.append("\n"+"   (직위)");
		chunk.setFont(normalFont);
		cell.setColspan(4);
		cell.add(chunk);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("   YYYY      MM    DD"+"\n",normalFont));
		chunk = new Chunk("    (년)       (월)    (일)"+"\n",normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk = new Chunk("   ");
		cell.add(chunk);
		chunk.append("2010");
		chunk.append("      ");
		chunk.append("08");
		chunk.append("      ");
		chunk.append("20"+"\n");
		chunk.setFont(normalFont);
		subscript = 5.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		chunk = new Chunk("........./......../......./");
		subscript = 15.0f;
		chunk.setTextRise(subscript);
		cell.add(chunk);
		cell.setColspan(4);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("   Telephone : ",normalFont));
		chunk = new Chunk("7. 042-342-3453",normalFont);
		chunk.append("\n"+"   (전화번호)");
		chunk.setFont(normalFont);
		cell.setColspan(2);
		cell.add(chunk);
		table.addCell(cell);
		
		cell = new Cell(new Chunk("   Fax : ",normalFont));
		chunk = new Chunk("7. 042-342-3453",normalFont);
		chunk.append("\n"+"   (팩스번호)");
		chunk.setFont(normalFont);
		cell.setColspan(2);
		cell.add(chunk);
		table.addCell(cell);

		document.add(table);
	}
}
